<template>
<div>
<!--     <el-upload
    class="upload-demo"
    :action="url"
    :headers="header"
    :on-preview="handlePreview"
    :on-remove="handleRemove"
    :on-success="progress"
    :data="userId"
    :file-list="fileList"
    list-type="picture"
  >
    <el-button size="small" type="primary">点击上传</el-button>
    <template #tip>
      <div class="el-upload__tip">只能上传 jpg/png 文件，且不超过 500kb</div>
    </template>
  </el-upload> -->
<single-upload v-model="user.urAvatar"></single-upload>
  <el-button type="primary" @click="update">确认修改</el-button>
</div>

</template>

<script>
import { getUserId, getToken } from "@/utils/auth";
import singleUpload from '@/components/upload/singleUpload'
import {update} from '@/api/user'
export default {
  components: { singleUpload },
  props: {
    user: {
      type: Object,
      default: () => {
        return {
          name: "",
          email: "",
        };
      },
    },
  },
  data() {
    return {
      header: { "sa-token": getToken() },
      url: process.env.VUE_APP_BASE_API + "/studentobject/user/upload",
      userId: { userId: getUserId() },
      fileList: [],
    };
  },
  methods: {
    update() {
         update(this.user).then(res=>{
          this.user=res.data.data
      })
      this.$message({
        message: "头像修改成功!",
        type: "success",
        duration: 5 * 1000,
      });
    },
  },
};
</script>